#ifndef SOCKET_SERVER_H_
#define SOCKET_SERVER_H_

#define PUERTO 5000
#define MAX_CONEXIONES 100
#define MAX_BUFFER 1024

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pthread.h>

void *socketHandler(void *lp) {
	uint32_t *csock = (uint32_t*)lp;

	char buffer[MAX_BUFFER];
	uint32_t buffer_len = MAX_BUFFER;
	uint32_t bytecount;

	memset(buffer, 0, buffer_len);
	if((bytecount = recv(*csock, buffer, buffer_len, 0))== -1){
		printf("Error en el recv()\n");
		free(csock);
	}

	printf("Recibidos %d bytes\nMensaje: \"%s\"\n", bytecount, buffer);

	if((bytecount = send(*csock, buffer, strlen(buffer), 0))== -1){
		printf("Error en el send()\n");
		free(csock);
	}

	printf("Enviados %d bytes\n", bytecount);

	free(csock);
	return 0;
}

#endif
